#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

	//先删除
    menuBar()->removeAction(ui->action_align_left);
    menuBar()->removeAction(ui->action_align_right);
    menuBar()->removeAction(ui->action_align_center);

	//再加回来
	QActionGroup* alignGroup = new QActionGroup(this);
	ui->menu_style->addAction(alignGroup->addAction(ui->action_align_left));
	ui->menu_style->addAction(alignGroup->addAction(ui->action_align_right));
	ui->menu_style->addAction(alignGroup->addAction(ui->action_align_center));

    QObject::connect(alignGroup, SIGNAL(triggered(QAction *)), this, SLOT(OnAlignmentTriggered(QAction *)));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_action_align_left_triggered()
{
    qDebug() << "left " << ui->action_align_left->isChecked() << "\n";
    //这个函数会执行,这条语句是没有意义的,因为用了QActionGroup,已经被选中好啦
	ui->action_align_left->setChecked(true);

    //对left对齐进行处理
}

void MainWindow::on_action_align_right_triggered()
{
    //这个函数会执行,这条语句是没有意义的,因为用了QActionGroup,已经被选中好啦
	ui->action_align_right->setChecked(true);

    //对right对齐进行处理
}

void MainWindow::on_action_align_center_triggered()
{
    //这个函数会执行,这条语句是没有意义的,因为用了QActionGroup,已经被选中好啦
	ui->action_align_center->setChecked(true);

    //对center对齐进行处理
}


void MainWindow::OnAlignmentTriggered(QAction* action)
{
    if (action == ui->action_align_left)
    {
        qDebug() << "left alignment" << "\n";
    }else if (action == ui->action_align_right)
    {
        qDebug() << "right alignment" << "\n";
    }else if (action == ui->action_align_center)
    {
        qDebug() << "center alignment" << "\n";
    }
}
